package com.cj.mobile.iabp.mvp.ui.activity;

import static com.jess.arms.utils.Preconditions.checkNotNull;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.bigkoo.pickerview.TimePickerView;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.cj.mobile.iabp.R;
import com.cj.mobile.iabp.app.dialog.PopupDropDownBoxWindow;
import com.cj.mobile.iabp.app.global.Constant;
import com.cj.mobile.iabp.app.utils.CommonUtils;
import com.cj.mobile.iabp.app.utils.DecimalInputUtils;
import com.cj.mobile.iabp.app.utils.EventBusTags;
import com.cj.mobile.iabp.app.utils.GlideLoader;
import com.cj.mobile.iabp.di.component.DaggerAddSurgeryInfoComponent;
import com.cj.mobile.iabp.mvp.contract.AddSurgeryInfoContract;
import com.cj.mobile.iabp.mvp.model.entity.DictInfo;
import com.cj.mobile.iabp.mvp.model.entity.MainEvent;
import com.cj.mobile.iabp.mvp.model.entity.SurgeryInfo;
import com.cj.mobile.iabp.mvp.presenter.AddSurgeryInfoPresenter;
import com.cj.mobile.iabp.mvp.ui.adapter.SecondaryDiagnosisAdapter;
import com.cj.mobile.iabp.mvp.ui.adapter.UploadCertificateAdapter;
import com.cj.mobile.iabp.mvp.ui.widget.FlexboxRadioGroup;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.base.DefaultAdapter;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.lcw.library.imagepicker.ImagePicker;

import org.simple.eventbus.Subscriber;
import org.simple.eventbus.ThreadMode;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import butterknife.BindView;
import butterknife.OnClick;
import permissions.dispatcher.NeedsPermission;
import permissions.dispatcher.OnNeverAskAgain;
import permissions.dispatcher.OnPermissionDenied;
import permissions.dispatcher.RuntimePermissions;

/**
 * Created on 2025/09/25 19:17
 * 添加患者手术信息
 *
 * @author Love_xie
 * module name is AddSurgeryInfoActivity
 */
@RuntimePermissions
public class AddSurgeryInfoActivity extends BaseActivity<AddSurgeryInfoPresenter> implements AddSurgeryInfoContract.View {
    /*----------------------------------------------------------------控件信息----------------------------------------------------------------*/
    @BindView(R.id.txvi_addsurgeryinfo_code)
    TextView txviCode;                                                                              // 登记号
    @BindView(R.id.txvi_addsurgeryinfo_name)
    TextView txviName;                                                                              // 患者姓名
    @BindView(R.id.edit_addsurgeryinfo_input_doctor)
    EditText editDoctor;                                                                            // 主管医生
    @BindView(R.id.revi_addsurgeryinfo_img)
    RecyclerView reviImgList;                                                                       // 拍照列表
    @BindView(R.id.revi_addsurgeryinfo_surgery_name)
    RecyclerView reviSurgeryName;                                                                   // 手术名称
    @BindView(R.id.edit_addsurgeryinfo_surgery_other)
    EditText editSurgeryOther;
    @BindView(R.id.group_addsurgeryinfo_workday)
    RadioGroup radioGroupWorkday;                                                                   // 是否工作日
    @BindView(R.id.txvi_addsurgeryinfo_surgery_time)
    TextView txviSurgery;                                                                           // 手术时间
    @BindView(R.id.imvi_addsurgeryinfo_surgery_time)
    ImageView imviSurgery;
    @BindView(R.id.txvi_addsurgeryinfo_install_time)
    TextView txviInstall;                                                                           // 安装时间
    @BindView(R.id.imvi_addsurgeryinfo_install_time)
    ImageView imviInstall;
    @BindView(R.id.lila_addsurgeryinfo_installer_input)
    LinearLayout lilaInstallerInput;
    @BindView(R.id.edit_addsurgeryinfo_installer_input)
    EditText editInstallerInput;                                                                    // 安装人员
    @BindView(R.id.lila_addsurgeryinfo_aides_input)
    LinearLayout lilaAidesInput;
    @BindView(R.id.edit_addsurgeryinfo_aides_input)
    EditText editAidesInput;                                                                        // 安装助手

    @BindView(R.id.radio_addsurgeryinfo_nyha_one)
    CheckBox cbNyhaOne;                                                                             // 术前心功能NYHA，一级
    @BindView(R.id.radio_addsurgeryinfo_nyha_two)
    CheckBox cbNyhaTwo;                                                                             // 术前心功能NYHA，二级
    @BindView(R.id.radio_addsurgeryinfo_nyha_three)
    CheckBox cbNyhaThree;                                                                           // 术前心功能NYHA，三级
    @BindView(R.id.radio_addsurgeryinfo_nyha_four)
    CheckBox cbNyhaFour;                                                                            // 术前心功能NYHA，四级

    @BindView(R.id.edit_addsurgeryinfo_input_fraction)
    EditText editFraction;                                                                          // 射血分数
    @BindView(R.id.edit_addsurgeryinfo_input_diameter)
    EditText editDiameter;                                                                          // 左室舒张末期内径
    @BindView(R.id.group_addsurgeryinfo_abscission)
    RadioGroup rgAbscission;                                                                        // 是否内膜脱落
    @BindView(R.id.edit_addsurgeryinfo_input_cpb)
    EditText editCpb;                                                                               // CPB时间
    @BindView(R.id.edit_addsurgeryinfo_input_interdiction)
    EditText editInterdiction;                                                                      // 阻断时间
    @BindView(R.id.edit_addsurgeryinfo_input_cabg)
    EditText editCabg;                                                                              // CABG支数

    @BindView(R.id.radio_addsurgeryinfo_corona_one)
    CheckBox cbCoronaOne;                                                                           // 冠状动脉病变部位 - LM
    @BindView(R.id.radio_addsurgeryinfo_corona_two)
    CheckBox cbCoronaTwo;                                                                           // 冠状动脉病变部位 - LAD
    @BindView(R.id.radio_addsurgeryinfo_corona_three)
    CheckBox cbCoronaThree;                                                                         // 冠状动脉病变部位 - DIAG
    @BindView(R.id.radio_addsurgeryinfo_corona_four)
    CheckBox cbCoronaFour;                                                                          // 冠状动脉病变部位 - LCX
    @BindView(R.id.radio_addsurgeryinfo_corona_5)
    CheckBox cbCoronaOm;                                                                            // 冠状动脉病变部位 - OM
    @BindView(R.id.radio_addsurgeryinfo_corona_6)
    CheckBox cbCoronaRCA;                                                                           // 冠状动脉病变部位 - RCA
    @BindView(R.id.radio_addsurgeryinfo_corona_7)
    CheckBox cbCoronaPDA;                                                                           // 冠状动脉病变部位 - PDA
    @BindView(R.id.radio_addsurgeryinfo_corona_8)
    CheckBox cbCoronaPLA;                                                                           // 冠状动脉病变部位 - PLA
    @BindView(R.id.radio_addsurgeryinfo_corona_9)
    CheckBox cbCoronaOther;                                                                         // 冠状动脉病变部位 - 其它

    @BindView(R.id.group_addsurgeryinfo_type)
    RadioGroup rgType;                                                                              // 球囊类型
    @BindView(R.id.group_addsurgeryinfo_qnnj)
    RadioGroup rgQnnj;                                                                              // 球囊内径
    @BindView(R.id.group_addsurgeryinfo_qnvolume)
    RadioGroup rgBalloonVolume;                                                                     // 球囊容积
    @BindView(R.id.group_addsurgeryinfo_placement)
    FlexboxRadioGroup rgPlacement;                                                                  // 置入位置
    @BindView(R.id.group_addsurgeryinfo_arterialsheath)
    RadioGroup rgArterialSheath;                                                                    // 是否动脉鞘
    @BindView(R.id.edit_addsurgeryinfo_input_ycgdmnj)
    EditText editYcgdmnj;                                                                           // 右侧股动脉内径
    @BindView(R.id.group_addsurgeryinfo_ycgdmxzcd)
    RadioGroup rgYcgdmxzcd;                                                                         // 右侧股动脉狭窄程度
    @BindView(R.id.group_addsurgeryinfo_rplaque)
    RadioGroup rgRplaque;                                                                           // 右侧股动脉斑块
    @BindView(R.id.edit_addsurgeryinfo_input_zcgdmnj)
    EditText editZcgdmnj;                                                                           // 左侧股动脉内径
    @BindView(R.id.group_addsurgeryinfo_zcgdmxzcd)
    RadioGroup rgZcgdmxzcd;                                                                         // 左侧股动脉狭窄程度
    @BindView(R.id.group_addsurgeryinfo_lplaque)
    RadioGroup rgLplaque;                                                                           // 左侧股动脉斑块
    @BindView(R.id.group_addsurgeryinfo_timing)
    FlexboxRadioGroup rgTiming;                                                                     // 安装时机
    @BindView(R.id.group_addsurgeryinfo_installstate)
    RadioGroup rgInstallState;                                                                      // 安装时状态
    @BindView(R.id.group_addsurgeryinfo_ecmo)
    RadioGroup rgEcmo;                                                                              // 联合ECMO
    @BindView(R.id.group_addsurgeryinfo_installaddress)
    FlexboxRadioGroup rgInstallAddress;                                                             // 安装地址
    @BindView(R.id.edit_addsurgeryinfo_installcause)
    EditText editInstallCause;                                                                      // 安装时应用原因、患者及安装情况

    @BindView(R.id.group_addsurgeryinfo_rhythm)
    FlexboxRadioGroup rgRhythm;                                                                     // 安装前心律
    @BindView(R.id.edit_addsurgeryinfo_rhythm_other)
    EditText editRhythmOther;
    @BindView(R.id.edit_addsurgeryinfo_input_heartrate)
    EditText editHeartrate;                                                                         // 安装前心率
    @BindView(R.id.edit_addsurgeryinfo_input_azqxy)
    EditText editAzqxy;                                                                             // 安装前血压


    @BindView(R.id.group_addsurgeryinfo_hrhythm)
    FlexboxRadioGroup rgHrhythm;                                                                    //安装后心律
    @BindView(R.id.edit_addsurgeryinfo_hrhythm_other)
    EditText editHrhythmOther;
    @BindView(R.id.edit_addsurgeryinfo_input_hheartrate)
    EditText editHheartrate;                                                                        // 安装后心率
    @BindView(R.id.edit_addsurgeryinfo_input_azhxy)
    EditText editAzhxy;                                                                             // 安装后血压

    @BindView(R.id.edit_addsurgeryinfo_input_azqdbaywl)
    EditText editAzqdbaywl;                                                                         // 安装前多巴胺药物量
    @BindView(R.id.edit_addsurgeryinfo_input_azqssxsywl)
    EditText editAzqssxsywl;                                                                        // 安装前肾上腺素药物量
    @BindView(R.id.edit_addsurgeryinfo_input_azqqjssxsywl)
    EditText editAzqqjssxsywl;                                                                      // 安装前去甲肾上腺素药物量
    @BindView(R.id.edit_addsurgeryinfo_input_azqmlnywl)
    EditText editAzqmlnywl;                                                                         // 安装前米力农药物量
    @BindView(R.id.edit_addsurgeryinfo_input_azqctywl)
    EditText editAzqctywl;                                                                          // 安装前垂体药物量
    @BindView(R.id.edit_addsurgeryinfo_input_azqdbfdaywl)
    EditText editAzqdbfdaywl;                                                                       // 安装前多巴酚丁胺药物量
    @BindView(R.id.edit_addsurgeryinfo_input_azqxgsys)
    EditText editAzqxgsys;                                                                          // 安装前血管升压素
    @BindView(R.id.edit_addsurgeryinfo_input_vis)
    EditText editAzqVis;                                                                            // 安装前VIS

    @BindView(R.id.edit_addsurgeryinfo_input_azhdbaywl)
    EditText editAzhdbaywl;                                                                         // 安装后多巴胺药物量
    @BindView(R.id.edit_addsurgeryinfo_input_azhssxsywl)
    EditText editAzhssxsywl;                                                                        // 安装后肾上腺素药物量
    @BindView(R.id.edit_addsurgeryinfo_input_azhqjssxsywl)
    EditText editAzhqjssxsywl;                                                                      // 安装后去甲肾上腺素药物量
    @BindView(R.id.edit_addsurgeryinfo_input_azhmlnywl)
    EditText editAzhmlnywl;                                                                         // 安装后米力农药物量
    @BindView(R.id.edit_addsurgeryinfo_input_azhctywl)
    EditText editAzhctywl;                                                                          // 安装后垂体药物量
    @BindView(R.id.edit_addsurgeryinfo_input_azhdbfdaywl)
    EditText editAzhdbfdaywl;                                                                       // 安装后多巴酚丁胺药物量
    @BindView(R.id.edit_addsurgeryinfo_input_azhxgsys)
    EditText editAzhxgsys;                                                                          // 安装后血管升压素
    @BindView(R.id.edit_addsurgeryinfo_input_hvis)
    EditText editHvis;                                                                              // 安装后VIS
    @BindView(R.id.edit_addsurgeryinfo_fbxggcwt)
    EditText editFbxggcwt;                                                                          // 反搏效果和反搏过程中出现问题
    @BindView(R.id.edit_addsurgeryinfo_input_machinecode)
    EditText editMachinecode;                                                                       // 机器代码
    @BindView(R.id.edit_addsurgeryinfo_input_iabp_ast)
    EditText editIabpAst;                                                                           // AST
    @BindView(R.id.edit_addsurgeryinfo_input_iabp_alt)
    EditText editIabpAlt;                                                                           // ALT
    @BindView(R.id.edit_addsurgeryinfo_input_iabp_jg)
    EditText editIabpCr;                                                                            // 肌酐Cr
    @BindView(R.id.edit_addsurgeryinfo_input_iabp_egfr)
    EditText editIabpEgfr;                                                                          // eGFR
    @BindView(R.id.edit_addsurgeryinfo_input_iabp_myo)
    EditText editIabpMyo;                                                                          // 肌红蛋白
    @BindView(R.id.edit_addsurgeryinfo_input_iabp_mmol)
    EditText editIabpMmol;                                                                          // 乳酸cLac
    @BindView(R.id.edit_addsurgeryinfo_input_iabp_jgdb)
    EditText editIabpJgdb;                                                                          // 肌钙蛋白
    @BindView(R.id.edit_addsurgeryinfo_input_iabp_xzdmcsts)
    EditText editIabpXzdmcsts;                                                                      // 下肢动脉超声特殊

    @BindView(R.id.edit_addsurgeryinfo_input_xzcs_azqls)
    EditText editXzcsAzqls;                                                                         // 安装前流速
    @BindView(R.id.edit_addsurgeryinfo_input_xzcs_gz)
    EditText editXzcsGz;                                                                            // 股总
    @BindView(R.id.edit_addsurgeryinfo_input_xzcs_gq)
    EditText editXzcsGq;                                                                            // 股浅
    @BindView(R.id.edit_addsurgeryinfo_input_xzcs_gs)
    EditText editXzcsGs;                                                                            // 股深
    @BindView(R.id.edit_addsurgeryinfo_input_xzcs_y)
    EditText editXzcsY;                                                                             // 胭
    @BindView(R.id.edit_addsurgeryinfo_input_xzcs_jq)
    EditText editXzcsJq;                                                                            // 胫前
    @BindView(R.id.edit_addsurgeryinfo_input_xzcs_jh)
    EditText editXzcsJh;                                                                            // 胫后
    @BindView(R.id.edit_addsurgeryinfo_input_xzcs_zb)
    EditText editXzcsZb;                                                                            // 足背

    @BindView(R.id.edit_addsurgeryinfo_input_xzcsh_azhls)
    EditText editXzcshAzhls;                                                                        // 安装后流速
    @BindView(R.id.edit_addsurgeryinfo_input_xzcsh_gz)
    EditText editXzcshGz;                                                                           // 股总
    @BindView(R.id.edit_addsurgeryinfo_input_xzcsh_gq)
    EditText editXzcshGq;                                                                           // 股浅
    @BindView(R.id.edit_addsurgeryinfo_input_xzcsh_gs)
    EditText editXzcshGs;                                                                           // 股深
    @BindView(R.id.edit_addsurgeryinfo_input_xzcsh_y)
    EditText editXzcshY;                                                                            // 胭
    @BindView(R.id.edit_addsurgeryinfo_input_xzcsh_jq)
    EditText editXzcshJq;                                                                           // 胫前
    @BindView(R.id.edit_addsurgeryinfo_input_xzcsh_jh)
    EditText editXzcshJh;                                                                           // 胫后
    @BindView(R.id.edit_addsurgeryinfo_input_xzcsh_zb)
    EditText editXzcshZb;                                                                           // 足背

    /*----------------------------------------------------------------业务信息----------------------------------------------------------------*/
    // 对话框
    private MaterialDialog mDialog;
    @Inject
    UploadCertificateAdapter mImgAdapter;
    @Inject
    GridLayoutManager mGridLayoutManager;

    @Named("surgeryLayout")
    @Inject
    RecyclerView.LayoutManager mLayoutManager;
    @Named("surgeryAdapter")
    @Inject
    SecondaryDiagnosisAdapter mAdapter;

    // 选择安装人员
    private PopupDropDownBoxWindow mPopupInstallPersonnel;
    // 选择安装助手
    private PopupDropDownBoxWindow mPopupInstallAides;

    // 时间
    private Date surgeryData, installData;

    @Override
    protected void onDestroy() {
        DefaultAdapter.releaseAllHolder(reviSurgeryName);
        DefaultAdapter.releaseAllHolder(reviImgList);
        KeyboardUtils.unregisterSoftInputChangedListener(getWindow());
        if (mDialog != null) {
            this.mDialog.dismiss();
        }
        super.onDestroy();

        this.mDialog = null;
        this.mImgAdapter = null;
        this.mGridLayoutManager = null;

        this.mAdapter = null;
        this.mLayoutManager = null;
        this.surgeryData = null;
        this.installData = null;
        if (this.mPopupInstallPersonnel != null) {
            this.mPopupInstallPersonnel.dismiss();
            this.mPopupInstallPersonnel = null;
        }
        if (this.mPopupInstallAides != null) {
            this.mPopupInstallAides.dismiss();
            this.mPopupInstallAides = null;
        }
    }

    /**
     * 根据主题使用不同的颜色。
     * 如果想要纯透明，则需要重写此方法，返回值为 -1 即可。
     */
    public int useStatusBarColor() {
        TypedValue typedValue = new TypedValue();
        getTheme().resolveAttribute(android.R.color.white, typedValue, true);
        return typedValue.data;
    }

    /**
     * 将状态栏改为浅色模式(状态栏 icon 和字体会变成深色)
     */
    public boolean useLightStatusBar() {
        return true;
    }

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerAddSurgeryInfoComponent
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_add_surgery_info;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        setTitle("手术信息");

        surgeryData = new Date();
        installData = new Date();
        // 初始化Loading对话框
        mDialog = new MaterialDialog.Builder(this).content(R.string.common_execute).progress(true, 0).build();

        initRecyclerView();
        setupListeners();

        // 创建输入框数组
        EditText[] decimalInputs = {editFraction, editDiameter, editCpb, editInterdiction, editCabg, editYcgdmnj,
                editZcgdmnj, editHeartrate, editHheartrate, editAzqdbaywl, editAzqssxsywl, editAzqqjssxsywl, editAzqmlnywl, editAzqctywl,
                editAzqdbfdaywl, editAzqxgsys, editAzqVis, editAzhdbaywl, editAzhssxsywl, editAzhqjssxsywl, editAzhmlnywl, editAzhctywl,
                editAzhdbfdaywl, editAzhxgsys, editHvis, editIabpAst, editIabpAlt, editIabpCr, editIabpEgfr, editIabpMyo,
                editIabpMmol, editIabpJgdb, editIabpXzdmcsts, editXzcsAzqls, editXzcsGz, editXzcsGq, editXzcsGs, editXzcsY,
                editXzcsJq, editXzcsJh, editXzcsZb, editXzcshAzhls, editXzcshGz, editXzcshGq, editXzcshGs, editXzcshY,
                editXzcshJq, editXzcshJh, editXzcshZb};
        // 批量设置，限制小数点后2位
        DecimalInputUtils.setupDecimalInputs(decimalInputs, 2);

        rgRhythm.setOnCheckedChangeListener((group, checkedId) -> {
            editRhythmOther.setVisibility(group.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_rhythm_other ? View.VISIBLE : View.GONE);
            editRhythmOther.setText("");
        });

        rgHrhythm.setOnCheckedChangeListener((group, checkedId) -> {
            editHrhythmOther.setVisibility(group.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_hrhythm_other ? View.VISIBLE : View.GONE);
            editHrhythmOther.setText("");
        });

        if (mPresenter != null) {
            mPresenter.initData(getIntent().getExtras());
        }
    }


    private void setupListeners() {
        // EditText 点击监听 - 显示PopupWindow和所有数据
        editInstallerInput.setOnClickListener(v -> {
            mPopupInstallPersonnel.showAllData();
            mPopupInstallPersonnel.show();
        });

        // EditText 文本变化监听 - 实时筛选
        editInstallerInput.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // 实时筛选数据
                if (mPopupInstallPersonnel != null) {
                    mPopupInstallPersonnel.filterData(s.toString());

                    // 如果PopupWindow没有显示，则显示它
                    if (!mPopupInstallPersonnel.isShowing()) {
                        mPopupInstallPersonnel.show();
                    }
                }
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });

        // EditText 焦点变化监听
        editInstallerInput.setOnFocusChangeListener((v, hasFocus) -> {
            if (hasFocus) {
                // 获取焦点时，如果文本为空，显示所有数据
                if (TextUtils.isEmpty(editInstallerInput.getText())) {
                    mPopupInstallPersonnel.showAllData();
                    mPopupInstallPersonnel.show();
                }
            } else {
                // 失去焦点时，延迟隐藏PopupWindow，避免与item点击冲突
                editInstallerInput.postDelayed(() -> {
                    if (!editInstallerInput.hasFocus()) {
                        mPopupInstallPersonnel.dismiss();
                    }
                }, 200);
            }
        });

        // 处理键盘完成按钮
//        editInstallerInput.setOnEditorActionListener((v, actionId, event) -> {
//            if (actionId == EditorInfo.IME_ACTION_DONE) {
//                mPopupInstallPersonnel.dismiss();
//                hideInput();
//                return true;
//            }
//            return false;
//        });

        /*--------------------------------------------------------------------------*/

        // EditText 点击监听 - 显示PopupWindow和所有数据
        editAidesInput.setOnClickListener(v -> {
            mPopupInstallAides.showAllData();
            mPopupInstallAides.show();
        });

        // EditText 文本变化监听 - 实时筛选
        editAidesInput.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // 实时筛选数据
                if (mPopupInstallAides != null) {
                    mPopupInstallAides.filterData(s.toString());

                    // 如果PopupWindow没有显示，则显示它
                    if (!mPopupInstallAides.isShowing()) {
                        mPopupInstallAides.show();
                    }
                }

            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });

        // EditText 焦点变化监听
        editAidesInput.setOnFocusChangeListener((v, hasFocus) -> {
            if (hasFocus) {
                // 获取焦点时，如果文本为空，显示所有数据
                if (TextUtils.isEmpty(editAidesInput.getText())) {
                    mPopupInstallAides.showAllData();
                    mPopupInstallAides.show();
                }
            } else {
                // 失去焦点时，延迟隐藏PopupWindow，避免与item点击冲突
                editAidesInput.postDelayed(() -> {
                    if (!editAidesInput.hasFocus()) {
                        mPopupInstallAides.dismiss();
                    }
                }, 200);
            }
        });

        // 处理键盘完成按钮
//        editAidesInput.setOnEditorActionListener((v, actionId, event) -> {
//            if (actionId == EditorInfo.IME_ACTION_DONE) {
//                mPopupInstallAides.dismiss();
//                hideInput();
//                return true;
//            }
//            return false;
//        });
    }

    @Subscriber(tag = EventBusTags.HOME_TAG, mode = ThreadMode.POST)
    private void eventBusEvent(MainEvent mainEvent) {
        if (mainEvent.getCode() == EventBusTags.UPLOAD_IMAGE_TAG) {
            // 上传图片
            AddSurgeryInfoActivityPermissionsDispatcher.getCameraWithPermissionCheck(this);
        } else if (mainEvent.getCode() == EventBusTags.DELETE_IMAGE_TAG) {
            // 删除照片
            if (mImgAdapter != null) {
                mImgAdapter.getInfos().remove(mainEvent.getPosition());
                mImgAdapter.notifyDataSetChanged();
            }
        } else if (mainEvent.getCode() == EventBusTags.SALE_SUCC_TAG) {
            // 手术名称
            DictInfo info = mainEvent.getInfo();
            if (info.getValue().contains("其他")) {
                editSurgeryOther.setVisibility(info.isCheckBox() ? View.VISIBLE : View.GONE);
                editSurgeryOther.setText("");
            }
        }
    }

    @OnClick({
            R.id.lila_addsurgeryinfo_surgery,                                                       // 手术时间 - 选择日期
            R.id.imvi_addsurgeryinfo_surgery_time,                                                  // 取消手术时间

            R.id.lila_addsurgeryinfo_install_time,                                                  // 安装时间 - 选择日期

            R.id.btn_addsurgeryinfo_vis_compute,                                                    // 安装前VIS计算
            R.id.btn_addsurgeryinfo_hvis_compute,                                                   // 安装后VIS计算

            R.id.btn_addsurgeryinfo_save,                                                           // 暂存
            R.id.btn_addsurgeryinfo_submit,                                                         // 提交
    })
    @Override
    public void onClick(View v) {
        hideInput();
        switch (v.getId()) {
            case R.id.lila_addsurgeryinfo_surgery:                                                  // 手术时间 - 选择日期
                onSurgeryDate();
                break;
            case R.id.imvi_addsurgeryinfo_surgery_time:                                             // 取消手术时间
                txviSurgery.setText("");
                imviSurgery.setVisibility(View.GONE);
                break;
            case R.id.lila_addsurgeryinfo_install_time:                                             // 安装时间 - 选择日期
                onInstallDate();
                break;
            case R.id.imvi_addsurgeryinfo_install_time:                                             // 取消安装时间
                txviInstall.setText("");
                imviInstall.setVisibility(View.GONE);
                break;
            case R.id.btn_addsurgeryinfo_vis_compute:                                               // 安装前VIS计算
                String afterBloodPasur = "";
//                String afterBloodPasur = editAzhxy.getText().toString();
//                if (TextUtils.isEmpty(afterBloodPasur)) {
//                    showMessage("请输入安装后血压！");
//                    return;
//                }

                String beforeDba = editAzqdbaywl.getText().toString();
                if (TextUtils.isEmpty(beforeDba)) {
                    showMessage("请输入安装前多巴胺药物量(ug/kg.min)！");
                    return;
                }

                String beforeSsx = editAzqssxsywl.getText().toString();
                if (TextUtils.isEmpty(beforeSsx)) {
                    showMessage("请输入安装前肾上腺素药物量(ug/kg.min)！");
                    return;
                }

                String beforeQjssx = editAzqqjssxsywl.getText().toString();
                if (TextUtils.isEmpty(beforeQjssx)) {
                    showMessage("请输入安装前去甲肾上腺素药物量(ug/kg.min)！");
                    return;
                }

                String beforeMln = editAzqmlnywl.getText().toString();
                if (TextUtils.isEmpty(beforeMln)) {
                    showMessage("请输入安装前米力农药物量！");
                    return;
                }

                String beforeDbf = editAzqdbfdaywl.getText().toString();
                if (TextUtils.isEmpty(beforeDbf)) {
                    showMessage("请输入安装前多巴酚丁胺药物量！");
                    return;
                }

                String beforeSys = editAzqxgsys.getText().toString();
                if (TextUtils.isEmpty(beforeSys)) {
                    showMessage("请输入安装前血管升压素！");
                    return;
                }

                if (mPresenter != null) {
                    mPresenter.calculateVISBeforeInstall(
                            afterBloodPasur,
                            beforeDba,
                            beforeSsx,
                            beforeQjssx,
                            beforeMln,
                            beforeDbf,
                            beforeSys
                    );
                }
                break;
            case R.id.btn_addsurgeryinfo_hvis_compute:                                              // 安装后VIS计算

                String afterDba = editAzhdbaywl.getText().toString();
                if (TextUtils.isEmpty(afterDba)) {
                    showMessage("请输入安装后多巴胺药物量(ug/kg.min)！");
                    return;
                }

                String afterSsx = editAzhssxsywl.getText().toString();
                if (TextUtils.isEmpty(afterSsx)) {
                    showMessage("请输入安装后肾上腺素药物量(ug/kg.min)！");
                    return;
                }

                String afterQjssx = editAzhqjssxsywl.getText().toString();
                if (TextUtils.isEmpty(afterQjssx)) {
                    showMessage("请输入安装后去甲肾上腺素药物量(ug/kg.min)！");
                    return;
                }

                String afterMln = editAzhmlnywl.getText().toString();
                if (TextUtils.isEmpty(afterMln)) {
                    showMessage("请输入安装后米力农药物量！");
                    return;
                }

                String afterDbf = editAzhdbfdaywl.getText().toString();
                if (TextUtils.isEmpty(afterDbf)) {
                    showMessage("请输入安装后多巴酚丁胺药物量！");
                    return;
                }

                String afterSys = editAzhxgsys.getText().toString();
                if (TextUtils.isEmpty(afterSys)) {
                    showMessage("请输入安装后血管升压素！");
                    return;
                }
                if (mPresenter != null) {
                    mPresenter.calculateVISAfterInstall(
                            afterDba,
                            afterSsx,
                            afterQjssx,
                            afterMln,
                            afterDbf,
                            afterSys);
                }
                break;
            case R.id.btn_addsurgeryinfo_save:                                                      // 暂存
                if (!CommonUtils.isDoubleClick()) {
                    onSubmit("0");
                }
                break;
            case R.id.btn_addsurgeryinfo_submit:                                                    // 提交
                if (!CommonUtils.isDoubleClick()) {
                    onSubmit("1");
                }
                break;
        }

    }

    /**
     * 提交事件
     */
    private void onSubmit(String pre) {

        if (mPresenter != null) {
            mPresenter.btnSubmit(pre,
                    editDoctor.getText().toString(),
                    mImgAdapter.getInfos(),
                    getSecondaryDiagnosis(),
                    editSurgeryOther.getText().toString(),
                    txviSurgery.getText().toString(),
                    txviInstall.getText().toString(),
                    getRestTime(),
                    editInstallerInput.getText().toString(),
                    editAidesInput.getText().toString(),
                    getNyha(),
                    editFraction.getText().toString(),
                    editDiameter.getText().toString(),
                    getIsOff(),
                    editCpb.getText().toString(),
                    editInterdiction.getText().toString(),
                    editCabg.getText().toString(),
                    getPlaceId(),
                    getBallType(),
                    getBallWidth(),
                    getBallSize(),
                    getPlace(),
                    getIsDmc(),
                    editYcgdmnj.getText().toString(),
                    getRightRoldHeight(),
                    getRightRoldHasColor(),
                    editZcgdmnj.getText().toString(),
                    getLeftRoldHeight(),
                    getLeftRoldHasColor(),
                    getInstallWhen(),
                    getInstallFor(),
                    getEcmoPlace(),
                    getInstallPlace(),
                    editInstallCause.getText().toString(),
                    getBeforeXinlv(),
                    editRhythmOther.getText().toString(),
                    editHeartrate.getText().toString(),
                    editAzqxy.getText().toString(),
                    getAfterXinlv(),
                    editHrhythmOther.getText().toString(),
                    editHheartrate.getText().toString(),
                    editAzhxy.getText().toString(),
                    editAzqdbaywl.getText().toString(),
                    editAzqssxsywl.getText().toString(),
                    editAzqqjssxsywl.getText().toString(),
                    editAzqmlnywl.getText().toString(),
                    editAzqctywl.getText().toString(),
                    editAzqdbfdaywl.getText().toString(),
                    editAzqxgsys.getText().toString(),
                    editAzqVis.getText().toString(),

                    editAzhdbaywl.getText().toString(),
                    editAzhssxsywl.getText().toString(),
                    editAzhqjssxsywl.getText().toString(),
                    editAzhmlnywl.getText().toString(),
                    editAzhctywl.getText().toString(),
                    editAzhdbfdaywl.getText().toString(),
                    editAzhxgsys.getText().toString(),
                    editHvis.getText().toString(),

                    editFbxggcwt.getText().toString(),
                    editMachinecode.getText().toString(),
                    editIabpAst.getText().toString(),
                    editIabpAlt.getText().toString(),
                    editIabpCr.getText().toString(),
                    editIabpEgfr.getText().toString(),
                    editIabpMyo.getText().toString(),
                    editIabpMmol.getText().toString(),
                    editIabpJgdb.getText().toString(),
                    editIabpXzdmcsts.getText().toString(),

                    editXzcsAzqls.getText().toString(),
                    editXzcsGz.getText().toString(),
                    editXzcsGq.getText().toString(),
                    editXzcsGs.getText().toString(),
                    editXzcsY.getText().toString(),
                    editXzcsJq.getText().toString(),
                    editXzcsJh.getText().toString(),
                    editXzcsZb.getText().toString(),

                    editXzcshAzhls.getText().toString(),
                    editXzcshGz.getText().toString(),
                    editXzcshGq.getText().toString(),
                    editXzcshGs.getText().toString(),
                    editXzcshY.getText().toString(),
                    editXzcshJq.getText().toString(),
                    editXzcshJh.getText().toString(),
                    editXzcshZb.getText().toString());
        }

    }

    private String getAfterXinlv() {
        if (rgHrhythm.getCheckedRadioButtonId() != -1) {
            if (rgHrhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_hrhythm_sinus) {
                return "窦";
            } else if (rgHrhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_hrhythm_fibrillation) {
                return "房颤";
            } else if (rgHrhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_hrhythm_ventricular) {
                return "室颤";
            } else if (rgHrhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_hrhythm_chamberspeed) {
                return "室速";
            } else if (rgHrhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_hrhythm_earlyroom) {
                return "室早";
            } else if (rgHrhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_hrhythm_pacing) {
                return "起搏";
            } else if (rgHrhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_hrhythm_notecg) {
                return "无心电活动";
            } else if (rgHrhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_hrhythm_other) {
                return "其它";
            }
        }
        return "";
    }

    private String getBeforeXinlv() {
        if (rgRhythm.getCheckedRadioButtonId() != -1) {
            if (rgRhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_rhythm_sinus) {
                return "窦";
            } else if (rgRhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_rhythm_fibrillation) {
                return "房颤";
            } else if (rgRhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_rhythm_ventricular) {
                return "室颤";
            } else if (rgRhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_rhythm_chamberspeed) {
                return "室速";
            } else if (rgRhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_rhythm_earlyroom) {
                return "室早";
            } else if (rgRhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_rhythm_pacing) {
                return "起搏";
            } else if (rgRhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_rhythm_notecg) {
                return "无心电活动";
            } else if (rgRhythm.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_rhythm_other) {
                return "其它";
            }
        }

        return "";
    }

    private String getInstallPlace() {
        if (rgInstallAddress.getCheckedRadioButtonId() != -1) {
            if (rgInstallAddress.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_installaddress_ward) {
                return "病房";
            } else if (rgInstallAddress.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_installaddress_operatingroom) {
                return "手术室";
            } else if (rgInstallAddress.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_installaddress_icu) {
                return "ICU";
            } else if (rgInstallAddress.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_installaddress_hurryup) {
                return "急抢";
            } else if (rgInstallAddress.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_installaddress_ccu) {
                return "CCU";
            } else if (rgInstallAddress.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_installaddress_other) {
                return "其它";
            }
        }
        return "";
    }

    private String getEcmoPlace() {
        if (rgEcmo.getCheckedRadioButtonId() != -1) {
            if (rgEcmo.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_ecmo_yes) {
                return "有";
            } else {
                return "无";
            }
        }


        return "";
    }

    private String getInstallFor() {
        if (rgInstallState.getCheckedRadioButtonId() != -1) {
            if (rgInstallState.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_installstate_prophylaxis) {
                return "预防";
            } else if (rgInstallState.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_installstate_rescue) {
                return "抢救";
            } else if (rgInstallState.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_installstate_forced) {
                return "被迫";
            }
        }

        return "";
    }

    private String getInstallWhen() {
        if (rgTiming.getCheckedRadioButtonId() != -1) {
            if (rgTiming.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_timing_before) {
                return "手术前";
            } else if (rgTiming.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_timing_inductionq) {
                return "诱导前";
            } else if (rgTiming.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_timing_inductionh) {
                return "诱导后";
            } else if (rgTiming.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_timing_middle) {
                return "术中";
            } else if (rgTiming.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_timing_postoperatively) {
                return "术后";
            }
        }
        return "";
    }

    private String getLeftRoldHasColor() {
        if (rgLplaque.getCheckedRadioButtonId() != -1) {
            if (rgLplaque.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_lplaque_y) {
                return "有";
            } else {
                return "无";
            }
        }

        return "";
    }

    private String getLeftRoldHeight() {
        if (rgZcgdmxzcd.getCheckedRadioButtonId() != -1) {
            if (rgZcgdmxzcd.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_zcgdmxzcd_no) {
                return "无";
            } else if (rgZcgdmxzcd.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_zcgdmxzcd_qing) {
                return "轻";
            } else if (rgZcgdmxzcd.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_zcgdmxzcd_middle) {
                return "中";
            } else if (rgZcgdmxzcd.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_zcgdmxzcd_heavy) {
                return "重";
            }
        }


        return "";
    }

    private String getRightRoldHasColor() {
        if (rgRplaque.getCheckedRadioButtonId() != -1) {
            if (rgRplaque.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_rplaque_y) {
                return "有";
            } else {
                return "无";
            }
        }

        return "";
    }

    private String getRightRoldHeight() {
        if (rgYcgdmxzcd.getCheckedRadioButtonId() != -1) {
            if (rgYcgdmxzcd.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_ycgdmxzcd_no) {
                return "无";
            } else if (rgYcgdmxzcd.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_ycgdmxzcd_qing) {
                return "轻";
            } else if (rgYcgdmxzcd.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_ycgdmxzcd_middle) {
                return "中";
            } else if (rgYcgdmxzcd.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_ycgdmxzcd_heavy) {
                return "重";
            }
        }

        return "";
    }


    private String getIsDmc() {
        if (rgArterialSheath.getCheckedRadioButtonId() != -1) {
            if (rgArterialSheath.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_arterialsheath_yes) {
                return "是";
            } else {
                return "否";
            }
        }

        return "";
    }

    private String getPlace() {
        if (rgPlacement.getCheckedRadioButtonId() != -1) {
            if (rgPlacement.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_placement_one) {
                return "左侧股动脉";
            } else if (rgPlacement.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_placement_two) {
                return "右侧股动脉";
            } else if (rgPlacement.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_placement_three) {
                return "腋动脉";
            } else if (rgPlacement.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_placement_si) {
                return "升主动脉";
            }
        }

        return "";
    }

    private String getBallSize() {
        if (rgBalloonVolume.getCheckedRadioButtonId() != -1) {
            if (rgBalloonVolume.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_volume_one) {
                return "30ml";
            } else if (rgBalloonVolume.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_volume_two) {
                return "40ml";
            } else if (rgBalloonVolume.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_volume_three) {
                return "50ml";
            }
        }

        return "";
    }

    private String getBallWidth() {
        if (rgQnnj.getCheckedRadioButtonId() != -1) {
            if (rgQnnj.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_one) {
                return "7F";
            } else if (rgQnnj.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_two) {
                return "7.5F";
            } else if (rgQnnj.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_three) {
                return "8F";
            }
        }

        return "";
    }

    private String getBallType() {
        if (rgType.getCheckedRadioButtonId() != -1) {
            if (rgType.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_arrow) {
                return "Arrow";
            } else {
                return "Data Scope";
            }
        }

        return "";
    }

    private String getPlaceId() {
        String values = "";
        if (cbCoronaOne.isChecked()) {
            if (TextUtils.isEmpty(values)) {
                values = cbCoronaOne.getText().toString();
            } else {
                values = values + "," + cbCoronaOne.getText().toString();
            }
        }

        if (cbCoronaTwo.isChecked()) {
            if (TextUtils.isEmpty(values)) {
                values = cbCoronaTwo.getText().toString();
            } else {
                values = values + "," + cbCoronaTwo.getText().toString();
            }
        }

        if (cbCoronaThree.isChecked()) {
            if (TextUtils.isEmpty(values)) {
                values = cbCoronaThree.getText().toString();
            } else {
                values = values + "," + cbCoronaThree.getText().toString();
            }
        }

        if (cbCoronaFour.isChecked()) {
            if (TextUtils.isEmpty(values)) {
                values = cbCoronaFour.getText().toString();
            } else {
                values = values + "," + cbCoronaFour.getText().toString();
            }
        }

        if (cbCoronaOm.isChecked()) {
            if (TextUtils.isEmpty(values)) {
                values = cbCoronaOm.getText().toString();
            } else {
                values = values + "," + cbCoronaOm.getText().toString();
            }
        }
        if (cbCoronaRCA.isChecked()) {
            if (TextUtils.isEmpty(values)) {
                values = cbCoronaRCA.getText().toString();
            } else {
                values = values + "," + cbCoronaRCA.getText().toString();
            }
        }
        if (cbCoronaPDA.isChecked()) {
            if (TextUtils.isEmpty(values)) {
                values = cbCoronaPDA.getText().toString();
            } else {
                values = values + "," + cbCoronaPDA.getText().toString();
            }
        }

        if (cbCoronaPLA.isChecked()) {
            if (TextUtils.isEmpty(values)) {
                values = cbCoronaPLA.getText().toString();
            } else {
                values = values + "," + cbCoronaPLA.getText().toString();
            }
        }

        if (cbCoronaOther.isChecked()) {
            if (TextUtils.isEmpty(values)) {
                values = cbCoronaOther.getText().toString();
            } else {
                values = values + "," + cbCoronaOther.getText().toString();
            }
        }

        return values;
    }

    private String getIsOff() {
        if (rgAbscission.getCheckedRadioButtonId() != -1) {
            if (rgAbscission.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_abscission_yes) {
                return "是";
            } else {
                return "否";
            }
        }

        return "";
    }


    private String getNyha() {
        String values = "";
        if (cbNyhaOne.isChecked()) {
            values = "I";
        }

        if (cbNyhaTwo.isChecked()) {
            if (TextUtils.isEmpty(values)) {
                values = "II";
            } else {
                values = values + ",II";
            }
        }

        if (cbNyhaThree.isChecked()) {
            if (TextUtils.isEmpty(values)) {
                values = "III";
            } else {
                values = values + ",III";
            }
        }

        if (cbNyhaFour.isChecked()) {
            if (TextUtils.isEmpty(values)) {
                values = "IV";
            } else {
                values = values + ",IV";
            }
        }
        return values;
    }

    private String getRestTime() {
        if (radioGroupWorkday.getCheckedRadioButtonId() != -1) {
            if (radioGroupWorkday.getCheckedRadioButtonId() == R.id.radio_addsurgeryinfo_weekday) {
                return "工作日";
            } else {
                return "节假日";
            }
        }
        return "";
    }


    /**
     * 获取选中的次要诊断
     */
    public String getSecondaryDiagnosis() {
        String result = "";

        for (DictInfo info : mAdapter.getInfos()) {
            if (info.isCheckBox()) {
                if (TextUtils.isEmpty(result)) {
//                    result = info.getCode();
                    result = info.getValue();
                } else {
//                    result = result + "," + info.getCode();
                    result = result + "," + info.getValue();
                }
            }
        }

        return result;
    }


    /**
     * 选择手术时间
     */
    private void onSurgeryDate() {
        // 起始日期
        Calendar startDate = Calendar.getInstance();
        // 设置年份
        startDate.set(Calendar.YEAR, 1900);

        // 终止日期(今天+100年)
        Calendar endDate = Calendar.getInstance();
        endDate.add(Calendar.YEAR, 100);

        TimePickerView pvOptions = new TimePickerView.Builder(this, (date, v) -> {
            this.surgeryData = date;
            // yyyy-MM-dd HH:mm:ss
            txviSurgery.setText(TimeUtils.date2String(date, new SimpleDateFormat("yyyy-MM-dd HH:mm")));
            imviSurgery.setVisibility(View.VISIBLE);
        })
                .setSubmitText("确定")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setSubCalSize(20)//确定和取消文字大小
                .setSubmitColor(ContextCompat.getColor(this, R.color.colorPrimary))//确定按钮文字颜色
                .setCancelColor(ContextCompat.getColor(this, R.color.colorPrimary))//取消按钮文字颜色
                .setTextColorCenter(Color.BLACK)//设置选中项的颜色
//                .setCyclic(true, true, true)//循环与否
                .setType(new boolean[]{true, true, true, true, true, false}) //年月日时分秒 的显示与否，不设置则默认全部显示
                .setRangDate(startDate, endDate)
                .setContentSize(16)
                .build();

        // 设置数据
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(surgeryData);
        pvOptions.setDate(calendar);
        pvOptions.show();
    }

    /**
     * 选择安装时间
     */
    private void onInstallDate() {
        // 起始日期
        Calendar startDate = Calendar.getInstance();
        // 设置年份
        startDate.set(Calendar.YEAR, 1900);

        // 终止日期(今天+100年)
        Calendar endDate = Calendar.getInstance();
        endDate.add(Calendar.YEAR, 100);

        TimePickerView pvOptions = new TimePickerView.Builder(this, (date, v) -> {
            this.installData = date;
            // yyyy-MM-dd HH:mm:ss
            txviInstall.setText(TimeUtils.date2String(date, new SimpleDateFormat("yyyy-MM-dd HH:mm")));
            imviInstall.setVisibility(View.VISIBLE);
        })
                .setSubmitText("确定")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setSubCalSize(20)//确定和取消文字大小
                .setSubmitColor(ContextCompat.getColor(this, R.color.colorPrimary))//确定按钮文字颜色
                .setCancelColor(ContextCompat.getColor(this, R.color.colorPrimary))//取消按钮文字颜色
                .setTextColorCenter(Color.BLACK)//设置选中项的颜色
//                .setCyclic(true, true, true)//循环与否
                .setType(new boolean[]{true, true, true, true, true, false}) //年月日时分秒 的显示与否，不设置则默认全部显示
                .setRangDate(startDate, endDate)
                .setContentSize(16)
                .build();

        // 设置数据
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(installData);
        pvOptions.setDate(calendar);
        pvOptions.show();
    }

    /**
     * 选择图片
     */
    @NeedsPermission({Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE})
    public void getCamera() {
        FileUtils.createOrExistsDir(Constant.IMAGE_PATH);

        ImagePicker.getInstance()
                .setTitle("图片")//设置标题
                .showCamera(true)//设置是否显示拍照按钮
                .showImage(true)//设置是否展示图片
                .showVideo(false)//设置是否展示视频
                .filterGif(true)//设置是否过滤gif图片
                .setMaxCount(getImageNum())//设置最大选择图片数目(默认为1，单选)
                .setSingleType(true)//设置图片视频不能同时选择
                .setImagePaths(galleryImages)
                .setImageLoader(new GlideLoader(getApplicationContext()))//设置自定义图片加载器
                .start(this, Constant.SELECT_IMG_GSMT_REQUESTCODE);
    }


    // 图库图片
    private ArrayList<String> galleryImages = new ArrayList<>();
    // 网络图片
    private ArrayList<String> networkImages = new ArrayList<>();

    /**
     * 图片可选数量
     * 逻辑：共可以选3张，假设列表中存在网络图片，则需要减去已存在的图片数量
     */
    private int getImageNum() {
        galleryImages.clear();
        networkImages.clear();
        // 一共可选图片数量
        int total = 3;
        // 网络图片数量
        int networkNum = 0;

        for (String str : mImgAdapter.getInfos()) {
            if (str.contains("http")) {
                networkNum++;
                networkImages.add(str);
            } else {
                galleryImages.add(str);
            }
        }

        return total - networkNum;
    }

    @OnPermissionDenied({Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE})
    void onCameraDenied() {
        // 用户拒绝权限时的处理
        showMessage("需要相机和存储权限才能选择图片");
    }

    @OnNeverAskAgain({Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE})
    void onCameraNeverAskAgain() {
        // 用户选择"不再询问"时的处理
        new MaterialDialog.Builder(this)
                .content("需要相机和存储权限才能选择图片，请在设置中手动开启权限")
                .positiveText("去设置")
                .negativeText("取消")
                .onPositive((dialog, which) -> {
                    // 引导用户到应用设置页面开启权限
                    CommonUtils.goToAppSettings(this);
                })
                .show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            // 照片
            if (requestCode == Constant.SELECT_IMG_GSMT_REQUESTCODE) {
                // 清空以前图片
                mImgAdapter.getInfos().clear();
                // 展示图片
                uploadData(data.getStringArrayListExtra(ImagePicker.EXTRA_SELECT_IMAGES), requestCode);
            }
        }
    }

    /**
     * 压缩失败 》 加载图片 》 添加默认选择的图片
     */
    private void uploadData(ArrayList<String> path, int requestCode) {
        // 照片
        if (requestCode == Constant.SELECT_IMG_GSMT_REQUESTCODE) {
            // 接收当前选中的图
            mImgAdapter.setData(networkImages);
            mImgAdapter.setData(path);
            // 接下来展示图片
            mImgAdapter.notifyDataSetChanged();
        }

    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        AddSurgeryInfoActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
    }

    private void initRecyclerView() {
        ArmsUtils.configRecyclerView(reviImgList, mGridLayoutManager);
        reviImgList.setAdapter(mImgAdapter);
        mImgAdapter.setDefaultBg(false);

        ArmsUtils.configRecyclerView(reviSurgeryName, mLayoutManager);
        reviSurgeryName.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener((view, viewType, data, position) -> {
            DictInfo item = (DictInfo) data;
        });
    }

    @Override
    public Activity getActivity() {
        return this;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public void showSurgeryInfo(String code, String name, SurgeryInfo info) {
        txviCode.setText(CommonUtils.isEmptyReturnStr(code, "暂无"));
        txviName.setText(CommonUtils.isEmptyReturnStr(name));
        if (info != null) {
            editDoctor.setText(CommonUtils.isEmptyReturnStr(info.getDoctorName()));

            if (!TextUtils.isEmpty(info.getImages())) {
                String[] path = info.getImages().split(",");

                // 接收当前选中的图
                mImgAdapter.setData(path);
                // 接下来展示图片
                mImgAdapter.notifyDataSetChanged();
            }

            if (!TextUtils.isEmpty(info.getSurgeryTime())) {
                txviSurgery.setText(info.getSurgeryTime());
                imviSurgery.setVisibility(View.VISIBLE);
            }

            if (!TextUtils.isEmpty(info.getInstallTime())) {
                txviInstall.setText(info.getInstallTime());
                imviInstall.setVisibility(View.VISIBLE);
            }

            if (!TextUtils.isEmpty(info.getRestTime())) {
                if (info.getRestTime().equals("工作日")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_weekday)).setChecked(true);
                } else {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_holidays)).setChecked(true);
                }
            }

            editInstallerInput.setText(CommonUtils.isEmptyReturnStr(info.getInstallMain()));
            editAidesInput.setText(CommonUtils.isEmptyReturnStr(info.getInstallSec()));

            if (!TextUtils.isEmpty(info.getNyha())) {
                String[] nyha = info.getNyha().split(",");
                for (String val : nyha) {
                    if (val.equals("I")) {
                        ((CheckBox) findViewById(R.id.radio_addsurgeryinfo_nyha_one)).setChecked(true);
                    } else if (val.equals("II")) {
                        ((CheckBox) findViewById(R.id.radio_addsurgeryinfo_nyha_two)).setChecked(true);
                    } else if (val.equals("III")) {
                        ((CheckBox) findViewById(R.id.radio_addsurgeryinfo_nyha_three)).setChecked(true);
                    } else {
                        ((CheckBox) findViewById(R.id.radio_addsurgeryinfo_nyha_four)).setChecked(true);
                    }
                }

            }

            editFraction.setText(CommonUtils.isEmptyReturnStr(info.getBloodScore()));
            editDiameter.setText(CommonUtils.isEmptyReturnStr(info.getLeftWidth()));

            if (!TextUtils.isEmpty(info.getIsOff())) {
                if (info.getIsOff().equals("是")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_abscission_yes)).setChecked(true);
                } else {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_abscission_no)).setChecked(true);
                }
            }

            editCpb.setText(CommonUtils.isEmptyReturnStr(info.getCpbMinits()));
            editInterdiction.setText(CommonUtils.isEmptyReturnStr(info.getStopNinits()));
            editCabg.setText(CommonUtils.isEmptyReturnStr(info.getCagb()));

            if (!TextUtils.isEmpty(info.getPlaceId())) {
                String[] placeId = info.getPlaceId().split(",");
                for (String val : placeId) {
                    if (val.equals("LM")) {
                        ((CheckBox) findViewById(R.id.radio_addsurgeryinfo_corona_one)).setChecked(true);
                    } else if (val.equals("LAD")) {
                        ((CheckBox) findViewById(R.id.radio_addsurgeryinfo_corona_two)).setChecked(true);
                    } else if (val.equals("DIAG")) {
                        ((CheckBox) findViewById(R.id.radio_addsurgeryinfo_corona_three)).setChecked(true);
                    } else if (val.equals("LCX")) {
                        ((CheckBox) findViewById(R.id.radio_addsurgeryinfo_corona_four)).setChecked(true);
                    } else if (val.equals("OM")) {
                        ((CheckBox) findViewById(R.id.radio_addsurgeryinfo_corona_5)).setChecked(true);
                    } else if (val.equals("RCA")) {
                        ((CheckBox) findViewById(R.id.radio_addsurgeryinfo_corona_6)).setChecked(true);
                    } else if (val.equals("PDA")) {
                        ((CheckBox) findViewById(R.id.radio_addsurgeryinfo_corona_7)).setChecked(true);
                    } else if (val.equals("PLA")) {
                        ((CheckBox) findViewById(R.id.radio_addsurgeryinfo_corona_8)).setChecked(true);
                    } else if (val.equals("其他")) {
                        ((CheckBox) findViewById(R.id.radio_addsurgeryinfo_corona_9)).setChecked(true);
                    }
                }
            }

            if (!TextUtils.isEmpty(info.getBallType())) {
                if (info.getBallType().equals("Arrow")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_arrow)).setChecked(true);
                } else {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_scope)).setChecked(true);
                }
            }

            if (!TextUtils.isEmpty(info.getBallWidth())) {
                if (info.getBallWidth().equals("7F")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_one)).setChecked(true);
                } else if (info.getBallWidth().equals("7.5F")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_two)).setChecked(true);
                } else {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_three)).setChecked(true);
                }
            }

            if (!TextUtils.isEmpty(info.getBallSize())) {
                if (info.getBallSize().equals("30ml")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_volume_one)).setChecked(true);
                } else if (info.getBallSize().equals("40ml")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_volume_two)).setChecked(true);
                } else {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_volume_three)).setChecked(true);
                }
            }

            if (!TextUtils.isEmpty(info.getPlace())) {
                if (info.getPlace().equals("左侧股动脉")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_placement_one)).setChecked(true);
                } else if (info.getPlace().equals("右侧股动脉")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_placement_two)).setChecked(true);
                } else if (info.getPlace().equals("腋动脉")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_placement_three)).setChecked(true);
                } else if (info.getPlace().equals("升主动脉")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_placement_si)).setChecked(true);
                }
            }

            if (!TextUtils.isEmpty(info.getIsDmc())) {
                if (info.getIsDmc().equals("是")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_arterialsheath_yes)).setChecked(true);
                } else {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_arterialsheath_no)).setChecked(true);
                }
            }

            editYcgdmnj.setText(CommonUtils.isEmptyReturnStr(info.getRightRoldWidth()));
            if (!TextUtils.isEmpty(info.getRightRoldHeight())) {
                if (info.getRightRoldHeight().equals("无")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_ycgdmxzcd_no)).setChecked(true);
                } else if (info.getRightRoldHeight().equals("轻")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_ycgdmxzcd_qing)).setChecked(true);
                } else if (info.getRightRoldHeight().equals("中")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_ycgdmxzcd_middle)).setChecked(true);
                } else if (info.getRightRoldHeight().equals("重")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_ycgdmxzcd_heavy)).setChecked(true);
                }
            }

            if (!TextUtils.isEmpty(info.getRightRoldHasColor())) {
                if (info.getRightRoldHasColor().equals("有")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_rplaque_y)).setChecked(true);
                } else if (info.getRightRoldHasColor().equals("无")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_rplaque_w)).setChecked(true);
                }
            }

            editZcgdmnj.setText(CommonUtils.isEmptyReturnStr(info.getLeftRoldWidth()));
            if (!TextUtils.isEmpty(info.getLeftRoldHeight())) {
                if (info.getLeftRoldHeight().equals("无")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_zcgdmxzcd_no)).setChecked(true);
                } else if (info.getLeftRoldHeight().equals("轻")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_zcgdmxzcd_qing)).setChecked(true);
                } else if (info.getLeftRoldHeight().equals("中")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_zcgdmxzcd_middle)).setChecked(true);
                } else if (info.getLeftRoldHeight().equals("重")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_zcgdmxzcd_heavy)).setChecked(true);
                }
            }

            if (!TextUtils.isEmpty(info.getLeftRoldHasColor())) {
                if (info.getLeftRoldHasColor().equals("有")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_lplaque_y)).setChecked(true);
                } else if (info.getLeftRoldHasColor().equals("无")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_lplaque_w)).setChecked(true);
                }
            }

            if (!TextUtils.isEmpty(info.getInstallWhen())) {
                if (info.getInstallWhen().equals("手术前")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_timing_before)).setChecked(true);
                } else if (info.getInstallWhen().equals("诱导前")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_timing_inductionq)).setChecked(true);
                } else if (info.getInstallWhen().equals("诱导后")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_timing_inductionh)).setChecked(true);
                } else if (info.getInstallWhen().equals("术中")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_timing_middle)).setChecked(true);
                } else {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_timing_postoperatively)).setChecked(true);
                }
            }

            if (!TextUtils.isEmpty(info.getInstallFor())) {
                if (info.getInstallFor().equals("预防")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_installstate_prophylaxis)).setChecked(true);
                } else if (info.getInstallFor().equals("抢救")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_installstate_rescue)).setChecked(true);
                } else {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_installstate_forced)).setChecked(true);
                }
            }

            if (!TextUtils.isEmpty(info.getEcmoPlace())) {
                if (info.getEcmoPlace().equals("有")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_ecmo_yes)).setChecked(true);
                } else if (info.getEcmoPlace().equals("无")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_ecmo_no)).setChecked(true);
                }
            }

            if (!TextUtils.isEmpty(info.getInstallPlace())) {
                if (info.getInstallPlace().equals("病房")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_installaddress_ward)).setChecked(true);
                } else if (info.getInstallPlace().equals("手术室")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_installaddress_operatingroom)).setChecked(true);
                } else if (info.getInstallPlace().equals("ICU")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_installaddress_icu)).setChecked(true);
                } else if (info.getInstallPlace().equals("急抢")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_installaddress_hurryup)).setChecked(true);
                } else if (info.getInstallPlace().equals("CCU")) {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_installaddress_ccu)).setChecked(true);
                } else {
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_installaddress_other)).setChecked(true);
                }
            }

            editInstallCause.setText(CommonUtils.isEmptyReturnStr(info.getInstallWhy()));
            if (!TextUtils.isEmpty(info.getBeforeXinlv())) {

                if (info.getBeforeXinlv().contains(",")) {
                    editRhythmOther.setVisibility(View.VISIBLE);
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_rhythm_other)).setChecked(true);

                    String[] beforeXinlv = info.getBeforeXinlv().split(",");
                    for (String item : beforeXinlv) {
                        if (item.contains("@_")) {
                            editRhythmOther.setText(item.replace("@_", ""));
                        }
                    }

                } else {
                    editRhythmOther.setVisibility(View.GONE);

                    if (info.getBeforeXinlv().equals("窦")) {
                        ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_rhythm_sinus)).setChecked(true);
                    } else if (info.getBeforeXinlv().equals("房颤")) {
                        ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_rhythm_fibrillation)).setChecked(true);
                    } else if (info.getBeforeXinlv().equals("室颤")) {
                        ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_rhythm_ventricular)).setChecked(true);
                    } else if (info.getBeforeXinlv().equals("室速")) {
                        ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_rhythm_chamberspeed)).setChecked(true);
                    } else if (info.getBeforeXinlv().equals("室早")) {
                        ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_rhythm_earlyroom)).setChecked(true);
                    } else if (info.getBeforeXinlv().equals("起搏")) {
                        ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_rhythm_pacing)).setChecked(true);
                    } else if (info.getBeforeXinlv().equals("无心电活动")) {
                        ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_rhythm_notecg)).setChecked(true);
                    }
                }

            }

            editHeartrate.setText(CommonUtils.isEmptyReturnStr(info.getBeforeXinlvSize()));
            editAzqxy.setText(CommonUtils.isEmptyReturnStr(info.getBeforeBloodPasur()));
            if (!TextUtils.isEmpty(info.getAfterXinlv())) {

                if (info.getAfterXinlv().contains(",")) {
                    editHrhythmOther.setVisibility(View.VISIBLE);
                    ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_hrhythm_other)).setChecked(true);

                    String[] result = info.getAfterXinlv().split(",");
                    for (String item : result) {
                        if (item.contains("@_")) {
                            editHrhythmOther.setText(item.replace("@_", ""));
                        }
                    }
                } else {
                    editHrhythmOther.setVisibility(View.GONE);

                    if (info.getAfterXinlv().equals("窦")) {
                        ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_hrhythm_sinus)).setChecked(true);
                    } else if (info.getAfterXinlv().equals("房颤")) {
                        ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_hrhythm_fibrillation)).setChecked(true);
                    } else if (info.getAfterXinlv().equals("室颤")) {
                        ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_hrhythm_ventricular)).setChecked(true);
                    } else if (info.getAfterXinlv().equals("室速")) {
                        ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_hrhythm_chamberspeed)).setChecked(true);
                    } else if (info.getAfterXinlv().equals("室早")) {
                        ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_hrhythm_earlyroom)).setChecked(true);
                    } else if (info.getAfterXinlv().equals("起搏")) {
                        ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_hrhythm_pacing)).setChecked(true);
                    } else if (info.getAfterXinlv().equals("无心电活动")) {
                        ((RadioButton) findViewById(R.id.radio_addsurgeryinfo_hrhythm_notecg)).setChecked(true);
                    }
                }
            }
            editHheartrate.setText(CommonUtils.isEmptyReturnStr(info.getAfterXinlvSize()));
            editAzhxy.setText(CommonUtils.isEmptyReturnStr(info.getAfterBloodPasur()));
            editAzqdbaywl.setText(CommonUtils.isEmptyReturnStr(info.getBeforeDba()));
            editAzqssxsywl.setText(CommonUtils.isEmptyReturnStr(info.getBeforeSsx()));
            editAzqqjssxsywl.setText(CommonUtils.isEmptyReturnStr(info.getBeforeQjssx()));
            editAzqmlnywl.setText(CommonUtils.isEmptyReturnStr(info.getBeforeMln()));
            editAzqctywl.setText(CommonUtils.isEmptyReturnStr(info.getBeforeCt()));
            editAzqdbfdaywl.setText(CommonUtils.isEmptyReturnStr(info.getBeforeDbf()));
            editAzqxgsys.setText(CommonUtils.isEmptyReturnStr(info.getBeforeSys()));
            editAzqVis.setText(CommonUtils.isEmptyReturnStr(info.getBeforeVis()));

            editAzhdbaywl.setText(CommonUtils.isEmptyReturnStr(info.getAfterDba()));
            editAzhssxsywl.setText(CommonUtils.isEmptyReturnStr(info.getAfterSsx()));
            editAzhqjssxsywl.setText(CommonUtils.isEmptyReturnStr(info.getAfterQjssx()));
            editAzhmlnywl.setText(CommonUtils.isEmptyReturnStr(info.getAfterMln()));
            editAzhctywl.setText(CommonUtils.isEmptyReturnStr(info.getAfterCt()));
            editAzhdbfdaywl.setText(CommonUtils.isEmptyReturnStr(info.getAfterDbf()));
            editAzhxgsys.setText(CommonUtils.isEmptyReturnStr(info.getAfterSys()));
            editHvis.setText(CommonUtils.isEmptyReturnStr(info.getAfterVis()));

            editFbxggcwt.setText(CommonUtils.isEmptyReturnStr(info.getProblemA()));
            editMachinecode.setText(CommonUtils.isEmptyReturnStr(info.getMachineCode()));
            editIabpAst.setText(CommonUtils.isEmptyReturnStr(info.getIabpAst()));
            editIabpAlt.setText(CommonUtils.isEmptyReturnStr(info.getIabpAlt()));
            editIabpCr.setText(CommonUtils.isEmptyReturnStr(info.getIabpCr()));
            editIabpEgfr.setText(CommonUtils.isEmptyReturnStr(info.getIabpEgfr()));
            editIabpMyo.setText(CommonUtils.isEmptyReturnStr(info.getIabpMyo()));
            editIabpMmol.setText(CommonUtils.isEmptyReturnStr(info.getIabpClac()));
            editIabpJgdb.setText(CommonUtils.isEmptyReturnStr(info.getIabpGa()));
            editIabpXzdmcsts.setText(CommonUtils.isEmptyReturnStr(info.getDownSpecial()));

            editXzcsAzqls.setText(CommonUtils.isEmptyReturnStr(info.getDownBeforeA()));
            editXzcsGz.setText(CommonUtils.isEmptyReturnStr(info.getDownBeforeB()));
            editXzcsGq.setText(CommonUtils.isEmptyReturnStr(info.getDownBeforeC()));
            editXzcsGs.setText(CommonUtils.isEmptyReturnStr(info.getDownBeforeD()));
            editXzcsY.setText(CommonUtils.isEmptyReturnStr(info.getDownBeforeE()));
            editXzcsJq.setText(CommonUtils.isEmptyReturnStr(info.getDownBeforeF()));
            editXzcsJh.setText(CommonUtils.isEmptyReturnStr(info.getDownBeforeG()));
            editXzcsZb.setText(CommonUtils.isEmptyReturnStr(info.getDownBeforeH()));

            editXzcshAzhls.setText(CommonUtils.isEmptyReturnStr(info.getDownAfterA()));
            editXzcshGz.setText(CommonUtils.isEmptyReturnStr(info.getDownAfterB()));
            editXzcshGq.setText(CommonUtils.isEmptyReturnStr(info.getDownAfterC()));
            editXzcshGs.setText(CommonUtils.isEmptyReturnStr(info.getDownAfterD()));
            editXzcshY.setText(CommonUtils.isEmptyReturnStr(info.getDownAfterE()));
            editXzcshJq.setText(CommonUtils.isEmptyReturnStr(info.getDownAfterF()));
            editXzcshJh.setText(CommonUtils.isEmptyReturnStr(info.getDownAfterG()));
            editXzcshZb.setText(CommonUtils.isEmptyReturnStr(info.getDownAfterH()));
        }
    }

    /**
     * 显示安装人员
     */
    @Override
    public void loadInstallPersonnel(List<DictInfo> list) {
        List<String> listName = new ArrayList<>();

        if (CommonUtils.isNotEmpty(list)) {
            for (DictInfo info : list) {
                listName.add(info.getValue());
            }
        }
        mPopupInstallPersonnel = new PopupDropDownBoxWindow(this, lilaInstallerInput, editInstallerInput, listName);
    }

    /**
     * 显示安装助手
     */
    @Override
    public void loadInstallAides(List<DictInfo> list) {
        List<String> listName = new ArrayList<>();

        if (CommonUtils.isNotEmpty(list)) {
            for (DictInfo info : list) {
                listName.add(info.getValue());
            }
        }
        mPopupInstallAides = new PopupDropDownBoxWindow(this, lilaAidesInput, editAidesInput, listName);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        hideInput();
        return super.onTouchEvent(event);
    }

    /**
     * 隐藏软键盘
     */
    private void hideInput() {
        KeyboardUtils.hideSoftInput(this);
    }

    @Override
    public void loadBeforeCalculateResult(double value) {
        editAzqVis.setText(String.valueOf(value));
    }

    @Override
    public void loadAfterCalculateResult(double value) {
        editHvis.setText(String.valueOf(value));
    }

    @Override
    public void showLoadingSubmit() {
        if (mDialog != null)
            mDialog.show();
    }

    @Override
    public void hideLoadingSubmit() {
        if (mDialog != null)
            mDialog.hide();
    }

    @Override
    public void showSurgeryNameOther(String replace) {
        editSurgeryOther.setVisibility(TextUtils.isEmpty(replace) ? View.GONE : View.VISIBLE);
        editSurgeryOther.setText(replace);
    }
}